<?php

/*
 * 
 */
session_start();
include_once dirname(__FILE__)."/src/daos/membership.php";
include_once dirname(__FILE__)."/conf/smarty.conf.php";
if(isset($_POST["mobile"])){  // 手机模式
	$user_name =  strval( $_POST["user_name"]);
	$user_password =  strval($_POST["user_psw"]);
	$userdao = new UsersDAO();
	$user = $userdao->getUserInfoByName($user_name);	
	if($user->getUserPsw() == $user_password){		
		$str = $user->getUserId();//json_encode($user);
		echo $str;
	}
	else{
		echo "-1";
	}
	exit();
}
elseif (isset($_POST['ajax'])) {	// ajax请求
	exit();
}
else{	// 正常显示页面
	// 设置标题
	$title = "登录系统";
	// 显示页面
	if(isset($_POST["user_name"]) && isset($_POST["user_psw"])){		
		$user_name =  strval( $_POST["user_name"]);
		$user_password =  md5(strval($_POST["user_psw"]));
		$userdao = new UsersDAO();
		$user = $userdao->getUserInfoByName($user_name);	
		if($user->getUserPsw() == $user_password){		
			// 设置session
			 $_SESSION["user_id"] = $user->getUserId();
			 // 页面跳转
			$info = "登录成功！";
			$url = "index.php";
		}
		else{
			// 页面跳转
			$info = "登录失败！";
			$url = "login.php";
		}
		$smarty->assign("title",$title);
		$smarty->assign("info",$info);
		$smarty->assign("url",$url);
		$smarty->display("info.html");
	}
	else
	{
		$smarty->assign("title",$title);
		$smarty->display("login.html");
	}
}
?>
